<?
require_once("mvc/action/Action.php");
require_once("cms/event/om/EventI18nPeer.php");

class EditAction extends Action {

    private $log;

    public function __construct() {
        $this->log =& LoggerManager::getLogger("EditAction");
    }

    public function execute(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        if($form->getEventI18n()->getEventI18nId() > 0) {

            $eventI18n = EventI18nPeer::retrieveByPk($form->getEventI18n()->getEventI18nId());
            if(!is_null($eventI18n)) {

                $form->setEventI18n($eventI18n);

                $form->setDay($eventI18n->getEvent()->getDate("d"));
                $form->setMonth($eventI18n->getEvent()->getDate("m"));
                $form->setYear($eventI18n->getEvent()->getDate("Y"));

                if(!is_null($eventI18n->getEvent()->getTime())) {
                    $form->setHour($eventI18n->getEvent()->getTime("H"));
                    $form->setMinute($eventI18n->getEvent()->getTime("i"));
                }

            } else {
                $this->log->error("No eventI18n found with id {$form->getEventI18n()->getEventI18nId()}.");
                $form->getEventI18n()->setEventI18nId("");

                if($form->getEventI18n()->getLanguageCode() === null)
                    $form->getEventI18n()->setLanguageCode(
                        $request->getContext()->getInitParameter(_Core::DEFAULT_LANGUAGE)
                    );
            }

        } else {

            if($form->getEventI18n()->getLanguageCode() === null)
                $form->getEventI18n()->setLanguageCode(
                    $request->getContext()->getInitParameter(_Core::DEFAULT_LANGUAGE)
                );

        }

        return $mapping->findForward("success");

    }

}
?>